CREATE TABLE APPUser
(  UserID char(12)      PRIMARY KEY,
   Username varchar(10) NOT NULL unique,
   UserPassword varchar(16) NOT NULL,
   Balance smallint     NOT NULL DEFAULT (0),
   DownloadPath varchar ,
   IsSeller tinyint CHECK(IsSeller IN(0,1)),
   Phonenumber char(11) NOT NULL,
)
GO
CREATE TABLE material
(MaterialID char(12) PRIMARY KEY,
 Materialname varchar(20) NOT NULL,
 Category varchar(20) NOT NULL,
 Price smallint NOT NULL,
 UserID char(12) FOREIGN KEY REFERENCES APPUser(UserID),
 Uploadtime timestamp NOT NULL,
 IsPass tinyint CHECK(IsPass IN(0,1)),
)
GO
CREATE TABLE APPOrder
(OrderID char(12) PRIMARY KEY,
 Cost smallint NOT NULL,
 Ordertime timestamp NOT NULL,
 IsPay tinyint CHECK(IsPay IN(0,1)),
 UserID char(12) FOREIGN KEY REFERENCES APPUser(UserID),
)
GO
CREATE TABLE APPOrder2
(APPOrderID char(12) PRIMARY KEY,
 OrderID char(12) FOREIGN KEY REFERENCES APPOrder(OrderID),
 MaterialID char(12) FOREIGN KEY REFERENCES material(MaterialID),
 UserID char(12) FOREIGN KEY REFERENCES APPUser(UserID),
)
GO
CREATE TABLE admini
(AdminiID char(12) PRIMARY KEY,
 Admininame tinyint NOT NULL,
 AdminiPassword varchar(20) NOT NULL,
 )
 GO
 CREATE TABLE manage
 (ManageID char(12) PRIMARY KEY,
  AdminiID char(12) FOREIGN KEY REFERENCES admini(AdminiID),
  UserID char(12) ,
  MaterialID char(12) ,
  doing varchar(20) NOT NULL,
  doingtime timestamp NOT NULL,
 )
 GO